/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Portions created by the Initial Developer are
 * Copyright (C) 2012 the Initial Developer.
 * All Rights Reserved.
 *
 * The Original Code is this.
 *
 * The Initial Developer of the Original Code is the author below.
 */ 
 /**
 * @file .h
 * @brief auto generated.
 * @author K.Ozaki
 * @date 2011/03/11
 */


/*
 * MessageQue.h
 *
 *  @date: 2011/03/11
 *  @author: ozaki
 */

#ifndef MESSAGEQUE_H_
#define MESSAGEQUE_H_

#include <mqueue.h>
#include <sys/stat.h>
#include "semi/util/StringUtil.h"
#include "semi/posix/SharedMemory.h"
#include "semi/posix/SignalAction.h"

namespace semi {

namespace posix {

class MessageQue {
public:

    //    MessageQue();
    MessageQue(std::string quename);

    virtual ~MessageQue();

    void init(std::string quename);
    std::string getQueName();

    int send(std::string, unsigned int prio);

    std::string receive(unsigned int prio);

    std::string notify(unsigned int prio);

    int terminate();

    static void terminateAll();
    static std::string toStringCurrentQue();
    static void debugPrintQue();

    static std::string createQuename(std::string quename);

    static std::string terminate_message;

private:

    std::string QueName;

    SharedMemory mqpl;
    void addQueName(); // send
    void removeQueName(); // receive
    //    int existsQueName();
    struct QueNamePool {
        char queName[64][32]; // QueName
        int count[64]; // que counter
        char flg; // breakmark;
    };
    static std::string toStringQues(bool bl);

    static std::string que_id_file_name;
    static int que_id_maxsize;

    static SignalAction* sig_action;

};

}

}

#endif /* MESSAGEQUE_H_ */
